package com.payment.ktb.utils;

import android.app.Activity;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by syd on 2016/4/26.
 */
public class ActivityUtils {

    public static Map<String,Activity> activities = new HashMap<String,Activity>();

    /**
     *activity入栈
     * @param activityKey
     * @param activityValue
     */
    public static void addActivity(String activityKey, Activity activityValue){

        activities.put(activityKey,activityValue);

    }

    /**
     *activity出栈
     * @param activityKey
     */
    public static void removeActivity(String activityKey){


        if (activities.containsKey(activityKey)) {
            activities.remove(activityKey);
        }

    }





    /**
     *移除所有activity
     */
    public static void removeAllActivity(){

        for (Map.Entry<String, Activity> entry : activities.entrySet()) {
            if (! entry.getValue().isFinishing()) {
                entry.getValue().finish();
            }
        }
        System.exit(0);
    }




    /**
     *移除所有activity除了指定的activityName
     */
    public static void removeAllActivityWithoutName(String activityName){

        for (Map.Entry<String, Activity> entry : activities.entrySet()) {
            if (! entry.getValue().isFinishing() && !entry.getKey().equals(activityName)) {
                entry.getValue().finish();
            }
        }
        System.exit(0);
    }

}
